package servlet;



import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;

public class AdminaddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      int aid=Integer.parseInt(request.getParameter("aid"));
      String name =request.getParameter("name");
      String sex=request.getParameter("sex");
      int age=Integer.parseInt(request.getParameter("age"));
      String tel=request.getParameter("tel");
      String address =request.getParameter("address");
      int wid=Integer.parseInt(request.getParameter("wid"));
        String sql ="INSERT INTO admin VALUES (?,?,?,?,?,?,?)";

        PreparedStatement ps;
        try {
            ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setInt(1,aid);
            ps.setString(2, name);
            ps.setString(3, sex);
            ps.setInt(4,age);
            ps.setString(5, tel);
            ps.setString(6, address);
            ps.setInt(7,wid);
            int up = ps.executeUpdate();
            if(up==1){
                request.getRequestDispatcher("administrator.jsp").forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }



    }
}
